<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box">
        <button class="btn">1</button>
        <button class="btn">2</button>
        <button class="btn">3</button>
        <button class="btn">4</button>
        <button class="btn">5</button>
    </div>
    <script>
        const btns = document.querySelectorAll('.btn')
        for(var i=0;i<btns.length;i++){  
            //1 var 改为let
            //2 使用this
            //3 使用自调用函数，把var的作用于封装在函数里面
            // btn.addEventListener('click',function(){
            //     var text = this.innerText
            //     console.log(text)
            // })
            // (function(i){
            //     var  btn = btns[i];
            //     btn.addEventListener('click',function(){
            //     var text = btn.innerText
            //     console.log(text)
            // })
            // })(i)
        }
        // console.log(btn)
    </script>
</body>
</html>